/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * @author Administrator
 * Date: 2010-7-6 上午08:55:23
 */
package com.ccxe.manage.dao.impl;

import java.util.List;
import java.util.Map;

import com.ccxe.manage.util.help.DaoHelper;

/**
 * MENU_ITEM 表 查询dao
 * 
 * @author wangyx
 * 
 */
public class MenuItemDaoImpl {

//	private static final Log logger = LogFactory.getLog(MenuItemDaoImpl.class);
	private DaoHelper dHelper = new DaoHelper();

	/**
	 * 由roleid获取权限树
	 * 
	 * @param roleId
	 * @return
	 * @throws Exception
	 */
	public List<Map<?, ?>> queryAllByRole(Object roleId) throws Exception {
		return dHelper.getListBySql(queryAllSql(roleId));
	}

	/**
	 * 
	 * @param id
	 * @return
	 */
	public String queryAllSql(Object id) {
		String sId = id.toString();
//		Integer iId = -1;
//		try {
//			iId = Integer.parseInt(sId);
//		} catch (NumberFormatException e) {
//			sId = "'" + sId + "'";
//		}
		sId = "'" + sId + "'";
		String sql = " select distinct t.menu_id id,t.parent_id pid,t.menu_nm name , "
				+ " decode(rtrim(to_char(concat(t.menu_id,'  '))) ,rtrim(to_char(concat(i.menu_id,'  '))),'url_ok','url_none') url "
				+ " from MENU_ITEM_TMP t ,C_menu_role i  where t.menu_id = i.menu_id(+) and  i.role_id (+)=  "
				+ sId + "  ";
//		logger.info("SQL:"+sql);
		return sql;
	}
}
